<template>
  <el-drawer
    :title="$t('message.tcxq')"
    size="60%"
    :visible.sync="isShowDrawer"
    @close="closeDrawer"
  >
    <div class="detail_header">
      <div class="sp_bew">
        <div class="left">
          <el-image v-if="detail.fullImgurl" :src="detail.fullImgurl" class="img" />
          <div class="title_wrap">
            <div>
              <span class="title">{{ detail.name }}</span>
              <span class="status">{{ detail.status === '1' ? $t('message.yqy'):$t('message.jy') }}</span>
            </div>
            <div class="placeholder9 mt10">
              <span>{{ $t('message.mrxssl') }}：{{ detail.circulationDay }}</span>
              <span class="ml10">{{ $t('message.xgsl') }}：{{ detail.memberLimit && detail.memberLimit >0 ?detail.memberLimit + $t('message.fen'):$t('message.bxg') }}</span>
            </div>
          </div>
        </div>
        <div class="right">
          <div class="item">
            <div class="key">{{ $t('message.zffsl') }}</div>
            <div class="value">{{ detail.circulationAll || $t('message.bxl') }}</div>
          </div>
          <div class="item">
            <div class="key">{{ $t('message.yxssl') }}</div>
            <div class="value">{{ detail.sellNum }}</div>
          </div>
          <div class="item">
            <div class="key">{{ $t('message.sysl2') }}</div>
            <div v-if="detail.circulationAll" class="value">{{ detail.surplusDay }}</div>
            <div v-else class="value">{{ detail.surplusDay || $t('message.bxl') }}</div>
          </div>
        </div>
      </div>
      <div class="createTime_wrap">
        <span class="item">{{ $t('message.createTime') }}：{{ detail.createTime }}</span>
        <span class="item">{{ $t('message.cjr') }}：{{ detail.creator }}</span>
        <span class="item">{{ $t('message.zhgxsj') }}：{{ detail.editTime }}</span>
        <span class="item">{{ $t('message.gxr') }}：{{ detail.editor }}</span>
      </div>
    </div>
    <div class="separate" />
    <div class="property-title">{{ $t('message.tcsx') }}</div>
    <div class="line">
      <div class="key">{{ $t('message.tcname') }}：</div>
      <div class="value">{{ detail.name }}</div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.tclx') }}：</div>
      <div v-if="detail.mealsType == '0'" class="value">{{ $t('message.mpck') }}</div>
      <div v-if="detail.mealsType == '1'" class="value">{{ $t('message.mpqxk') }}</div>
      <div v-if="detail.mealsType == '2'" class="value">{{ $t('message.ydck') }}</div>
      <div v-if="detail.mealsType == '3'" class="value">{{ $t('message.kcyyck') }}</div>
      <div v-if="detail.mealsType == '4'" class="value">{{ $t('message.kcqxk') }}</div>
    </div>
    <div class="line">
      <div class="key">{{ detail.mealsType == '1' || detail.mealsType == '4' ? $t('message.mrcrxz') + '：': $t('message.tccs') + '：'}}</div>
      <div v-if="detail.mealsType == '1' || detail.mealsType == '4'" class="value">
        <span>{{ detail.inOutNum || $t('message.bxz') }}</span>
      </div>
      <div v-else class="value"><span>{{ detail.nums }}</span></div>
    </div>
    <div v-if="detail.giveNums && detail.mealsType != '1'" class="line">
      <div class="key">{{ $t('message.zscs') }}：</div>
      <div class="value">{{ detail.giveNums }}</div>
    </div>
    <div v-if="detail.transferValue" class="line">
      <div class="key">{{ $t('message.zr') }}：</div>
      <div class="value">{{ detail.transferValue }}{{ detail.transferValueType =="2"?'%':$t('message.yuan') }}</div>
    </div>
    <div v-if="detail.freezeValue" class="line">
      <div class="key">{{ $t('message.dj') }}：</div>
      <div class="value">{{ detail.freezeValue }}{{ detail.freezeValueType =="2"?'%':$t('message.yuan') }}</div>
    </div>
    <div v-if="detail.price" class="line">
      <div class="key">{{ $t('message.jgy') }}：</div>
      <div class="value">{{ detail.price }}</div>
    </div>
    <div v-if="detail.channel" class="line">
      <div class="key">{{ $t('message.xsqd') }}：</div>
      <div class="value">
        <span v-for="item,index in detail.channel" :key="item">
          {{ channels[item] }}
          <span v-if="index != detail.channel.length - 1">、</span>
        </span>
      </div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.sysm') }}：</div>
      <div class="value">
        <div>{{ detail.content }}</div>
      </div>
    </div>

    <div class="property-title">{{ $t('message.sjsz') }}</div>
    <div class="line">
      <div class="key">{{ $t('message.xssj') }}：</div>
      <div class="value">{{ detail.saleDateStart }} {{ $t('message.zhi2') }} {{ detail.saleDateEnd }}</div>
    </div>
    <div class="line" @click="showKysj = !showKysj">
      <div class="key">{{ $t('message.sysj') }}：</div>
      <div v-if="detail.validityType === '0'" class="value">{{ $t('message.gdrq') }}：{{ detail.validityStartTime }} {{ $t('message.zhi2') }} {{ detail.validityEndTime }}</div>
      <div v-if="detail.validityType === '1'" class="value">{{ $t('message.yxq') }}：{{ detail.indate }}{{ $t('message.tian') }}</div>
      <div v-if="detail.validityType === '2'" class="value">{{ detail.assignValidTime }}{{ $t('message.kssx') }}</div>
    </div>
    <div class="line" @click="showSjd = !showSjd">
      <div class="key">{{ $t('message.sjdxz') }}：</div>
      <div class="value">{{ detail.useTimeInfo }}</div>
    </div>

    <div class="property-title">{{ $t('message.hyzk') }}</div>
    <div>
      <div class="flex1 line">
        <span class="key">{{ $t('message.zklx') }}：</span>
        <span class="value">{{
          detail.discountType === "1" ? $t('message.zdyzk') :$t('message.mrzk')
        }}</span>
      </div>
    </div>
    <div v-if="detail.discountType === '1'" class="mt20 discount_wrap">
      <div v-for="item in vipTypes" :key="item.id" class="discount">
        <span v-if="item && item.name" class="key">{{ item.name }}：</span>
        <span class="value">{{ item.value * 10 }}{{ $t('message.zhe') }}</span>
      </div>
    </div>

    <div class="property-title">{{ $t('message.sygz') }}</div>
    <div class="line">
      <div class="key">{{ $t('message.zffsl') }}：</div>
      <div class="value">{{ detail.circulationAll || $t('message.bxl') }}</div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.rffsl') }}：</div>
      <div class="value">{{ detail.circulationDay }}</div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.sycg') }}：</div>
      <div class="value">{{ detail.useVenue }}</div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.syxm') }}：</div>
      <div class="value">{{ detail.useProject }}</div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.kykcxz') }}：</div>
      <div class="value">{{ detail.useClassInfo }}</div>
    </div>
    <div class="line">
      <div class="key">{{ $t('message.kyjlxz') }}：</div>
      <div class="value">{{ detail.useTeacherInfo }}</div>
    </div>
  </el-drawer>
</template>

<script>
import {
  mealInfob,
  cardList
} from '@/api'
export default {
  name: 'ComboAdd',
  data() {
    return {
      isShowDrawer: false,
      detail: {},
      vipTypes: [],
      channels: {
        '1': this.$t('message.xcx'),
        '2': this.$t('message.cgd')
      }
    }
  },
  methods: {
    closeDrawer() {
      this.isShowDrawer = false
      this.$emit('close')
    },
    getMealInfo(id) {
      mealInfob({
        param: { id }
      }).then(res => {
        if (res.errorCode !== '000000') return
        this.detail = { ...res.record }
      })
    },
    getTicketDetail(id) {
      // 详情 获取卡类型列表 默认票样式 现有项目
      Promise.all([
        mealInfob({ param: { id }}),
        cardList({
          pagination: {
            page: 1,
            rows: 1000,
            firstQueryTime: this.firstQueryTime
          },
          param: {
            cardName: null,
            isnormal: null,
            channel: '',
            type: '1'
          }
        })
      ])
        .then((res) => {
          this.detail = { ...res[0].record }
          this.detail.channel = this.detail.channel.split(',')

          const discountmap = res[0].record.discount

          if (this.detail.discountType === '1') {
            res[1].recordList.forEach((item) => {
              if (item.status === '1') {
                this.vipTypes.push({
                  name: item.cardName,
                  id: item.id,
                  value: discountmap[item.id] || 1
                })
              }
            })
          }
          if (res[0].record.discountType === '0') {
            this.$set(this.detail, 'discountMap', {})
          } else {
            this.$set(this.detail, 'discountMap', discountmap)
          }
        })
        .catch((err) => {
          console.log(err)
        })
    }
  }
}
</script>

<style lang="scss" scoped>
@import "@/styles/variables.scss";

.line{
  display: flex;
  align-items: center;
  margin-bottom: 20px;
  font-size: 14px;
  // padding-left: 16px;
  .key{
    color: #666666;
  }
  .value{
    color: #222222;
  }
}
.discount_wrap {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  padding-left: 34px;
  font-size: 14px;
  .key {
    width: 90px;
  }
  .discount {
    width: 33.33%;
    margin-bottom: 20px;
  }
}
.detail_header{
  font-size: 14px;
  .sp_bew{
    display: flex;
    justify-content: space-between;
    .left{
      display: flex;
      .img{
        width: 50px;
        height: 50px;
        margin-right: 20px;
      }
      .title{
        font-size: 18px;
        font-weight: 600;
        color: #222222;
      }
      .status{
        border-radius: 2px;
        border: 1px solid $primaryColor;
        color: $primaryColor;
        margin-left: 10px;
      }
    }
    .right{
      display: flex;
      background-color: #F4F7FC;
      border-radius: 2px;
      .item{
        padding: 14px 20px;
        .key{
          font-size: 12px;
          color: #666666;
        }
        .value{
          margin-top: 8px;
          color: #222222;
          font-weight: 600;
        }
      }
    }
  }
  .createTime_wrap{
    display: flex;
    justify-content: flex-end;
    margin: 16px 0;
    .item{
      margin-left: 30px;
      color: #999999;
    }
  }
}
.separate{
  height: 1px;
  margin: 20px -20px;
  padding: 0 20px;
  background-color: #DFE2E8;
}
.tip {
  font-size: 14px;
  line-height: 1.5;
  color: #333;
}

.device-uploader {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #fff;
  cursor: pointer;
  border: 1px dashed #ccc;
  border-radius: 8px;
  transition: all 0.3s;
  margin-right: 20px;

  &:hover {
    border-color: $menuActive;

    .uploader-icon {
      color: $menuActive;
    }
  }

  ::v-deep .el-upload {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;

    .file {
      width: 100%;
      height: 100%;
      position: absolute;
      top: 0;
      left: 0;
      background-size: contain;
      background-position: center;
      background-repeat: no-repeat;
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;

      .delete {
        background-color: rgba(0, 0, 0, 0.5);
        position: absolute;
        width: 100%;
        height: 100%;
        top: 0;
        left: 0;
        display: none;
        align-items: center;
        justify-content: center;

        .icon {
          color: #fff;
        }
      }

      &:hover {
        .delete {
          display: flex;
        }
      }
    }
  }

  .uploader-icon {
    color: #aaaaaa;
    font-size: 22px;
    transition: all 0.3s;
  }
}
.count-style {
  display: inline-block;
  width: 45%;
  height: 60px;
}

.division-line {
  text-align: center;
  display: inline-block;
  color: #999;
  width: 50px;
}

.clock {
  display: inline-block;
}

.upload-style {
  vertical-align: middle;
  display: inline-block;
  // width: 60px;
  // height: 60px;
  border: none;
}

.img-style {
  margin: auto;
  background-color: #eee;
  width: 90px;
  height: 60px;
  vertical-align: middle;
}

.avatar {
  width: 60px;
  height: 60px;
  display: block;
}

.line-style {
  background-color: #dfe2e8;
  height: 1px;
  // width: 80%;
  // margin: 0 auto;
  margin-bottom: 20px;
}
</style>
